package dbz.domain.hand;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.Predicate;

import dbz.domain.Card;
import dbz.domain.Ki;

public class Hand {



	public List<Card> cards;
	
	public Hand() {
		cards = new ArrayList<Card>();
	}
	
	public void addCard(Card card) {
		cards.add(card);
	}

	public Boolean hasNKiCards(Integer n) {
		return countKiCards() == n;
		
	}

	public Boolean hasKiCard() {
		return countKiCards() > 0;
	}
	
	public Integer countKiCards() {
		return CollectionUtils.countMatches(cards, new IsKiCardPredicate());
	}
	
	
	public class IsKiCardPredicate implements Predicate {

		@Override
		public boolean evaluate(Object arg0) {
			return arg0.getClass().equals(Ki.class);
		}

	}

	public Integer size() {
		return cards.size();
	}

	public List<Card> getCards() {
		return cards;
	}

	public void setCards(List<Card> cards) {
		this.cards = cards;
	}


	public Ki getAnyKiCard() {
		return (Ki) CollectionUtils.find(cards, new IsKiCardPredicate());
	}
}
